package swing.frame.whiteboard;


import api.BoardServer;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class MenuPanel extends JPanel {
    JPanel panel=new JPanel();
    MyDrawPanel myDrawPanel;
    JButton button1;
    JButton button3;
    String menu;
    DrawPanel dp=new DrawPanel();
    public MenuPanel(MyDrawPanel myDrawPanel){
        this.myDrawPanel = myDrawPanel;
        init();
    }
    public void init(){
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        panel.setLayout(new GridLayout(1,5,4,4));

        button1 = new JButton("保存");
        button1.setActionCommand("保存");
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                BoardServer.boardService.saveBoard(myDrawPanel.whiteboard.getId());
            }
        });
        panel.add(button1);

        button3 = new JButton("清空");
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ImageIcon icon=new ImageIcon("image/alert.png");
                int i=JOptionPane.showConfirmDialog(myDrawPanel.dp,"确定要清空吗？","清空提示",2,1,icon);
                if(i==0){
                    myDrawPanel.dp.clearBoard();
                    BoardServer.boardService.clearBoard(myDrawPanel.whiteboard.getId());
                }
            }
        });
        panel.add(button3);
        this.add(panel);
        }
}


